package com.aaa.controller;

import com.aaa.pojos.Dept;
import com.aaa.pojos.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.aaa.service.DeptService;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class DeptController {
    @Resource
    private DeptService deptService;

    @GetMapping("/depts")
    public Result geiQueryAll(){
        log.info("查询所有部门信息");
        List<Dept> depts = deptService.queryAll();
        return Result.success(depts);
    }

    @DeleteMapping("/depts")
//    @RequestPara(value="表单参数",required=是否必须要有参数)
    public Result deleteById(@RequestParam(value = "id",required = true) Integer id){
        log.info("根据id删除部门信息");
      deptService.deleteById(id);
      return Result.success();
    }

    @PostMapping("/depts")
    public Result addDept(@RequestBody Dept dept){
        log.info("添加部门信息");
        deptService.addDept(dept);
        return Result.success();
    }

    @GetMapping("/depts/{id}")
    public Result getDeptById(@PathVariable("id") Integer id){
        log.info("根据id查询部门信息");
        Dept dept=deptService.getById(id);
        return Result.success(dept);
    }

    @PutMapping("/depts")
    public Result upDateDept(@RequestBody Dept dept){
        log.info("修改部门信息");
        deptService.updateDept(dept);
        return Result.success();
    }

}
